﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.IO;
using MathLib;

namespace Demog {
    class IOUtilities {
        public IOUtilities() {
        }
       
     public DataTable LoadToDataTable(string fileName) {
            ExcelReader rdr = new ExcelReader(fileName);
            DataSet ds = rdr.ReadData();
            return ds.Tables.Count > 0 ? ds.Tables[0] : null;
        }


     public Matrix ReadMatrixFromTable(DataTable dt) {
         Matrix m = new Matrix(dt.Rows.Count, dt.Columns.Count);

         for (int i = 0; i < m.NoRows; i++) {
             DataRow dr = dt.Rows[i];
             for (int j = 0; j < m.NoCols; j++) {
                 object val = dr[j];
                 try {
                     m[i, j] = DBNull.Value.Equals(val) ? 0.0 : (double)val;
                 } catch (Exception e) {
                     throw new Exception("Ошибка формата входных данных");
                 }
             }
         }

         return m;
     }


    }

}
